package com.dengyafei.controller;

import com.dengyafei.annotation.JwtToken;
import com.dengyafei.bean.DeliveryEntity;
import com.dengyafei.constant.RecommendConstant;
import com.dengyafei.constant.ResultMessage;
import com.dengyafei.domin.dto.DeliveryNumberCompanyDTO;
import com.dengyafei.domin.dto.DeliveryNumberPositionDTO;
import com.dengyafei.domin.vo.*;
import com.dengyafei.result.PageEntity;
import com.dengyafei.result.RestApiResult;
import com.dengyafei.service.DeliveryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 邓亚非
 */
@RestController
@RequestMapping("/delivery")
@Slf4j
public class DeliveryController {

    @Autowired
    DeliveryService deliveryService;

    /**
     * 查询投递岗位
     *
     * @param pageVo
     * @return
     */
    @JwtToken
    @PostMapping(value = "/queryDeliveryByHid")
    public RestApiResult queryDeliveryByHid(@RequestBody PageVo pageVo) {
        log.info("【职位投递模块-查询投递信息接口-参数】pageVo:[{}]", pageVo);
        PageEntity<DeliveryEntity> pageEntity = deliveryService.queryByHid(pageVo);
        log.info("【职位投递模块-查询投递信息接口-成功】pageVo:[{}]", ResultMessage.Delivery.DELIVERY_QUERY_SUCCESS);
        return RestApiResult.ok(pageEntity);
    }

    /**
     * 拒绝投递
     *
     * @param deliveryRefuseVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/refuseDelivery")
    public RestApiResult refuseDelivery(@RequestBody DeliveryRefuseVO deliveryRefuseVO) {
        log.info("【岗位投递模块-拒绝接口-参数】deliveryRefuseVO:[{}]", deliveryRefuseVO);
        Integer integer = deliveryService.refuseDelivery(deliveryRefuseVO);
        if (!integer.equals(RecommendConstant.OPERATION_SUCCESS)) {
            log.error("【岗位投递模块-拒绝接口-失败】deliveryRefuseVO,cause:[{}]", ResultMessage.Delivery.DELIVERY_REFUSE_FAILURE);
            return RestApiResult.error(ResultMessage.Delivery.DELIVERY_REFUSE_FAILURE);
        }
        log.info("【岗位投递模块-拒绝接口-成功】deliveryRefuseVO:[{}]", ResultMessage.Delivery.DELIVERY_REFUSE_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Delivery.DELIVERY_REFUSE_SUCCESS);
    }

    /**
     * 投递简历
     *
     * @param deliveryResumeVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "deliveryResume")
    public RestApiResult deliveryResume(@RequestBody DeliveryResumeVO deliveryResumeVO) {
        log.info("【投递模块-投递简历接口-参数】deliveryResumeVO:[{}]", deliveryResumeVO);
        Integer integer = deliveryService.deliveryResume(deliveryResumeVO);
        if (integer.equals(RecommendConstant.ALREADY_DELIVERY)) {
            log.error("【投递模块-投递简历接口-失败】deliveryResumeVO,cause:[{}]", ResultMessage.Delivery.ALREADY_DELIVERY);
            return RestApiResult.error(ResultMessage.Delivery.ALREADY_DELIVERY);
        }
        if (!integer.equals(RecommendConstant.OPERATION_SUCCESS)) {
            log.error("【投递模块-投递简历接口-失败】deliveryResumeVO,cause:[{}]", ResultMessage.Delivery.DELIVERY_FAILURE);
            return RestApiResult.error(ResultMessage.Delivery.DELIVERY_FAILURE);
        }
        log.info("【投递模块-投递简历接口-成功】deliveryResumeVO:[{}]", ResultMessage.Delivery.DELIVERY_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Delivery.DELIVERY_SUCCESS);
    }

    /**
     * 根据gid查询投递的岗位
     *
     * @param pageVo
     * @return
     */
    @JwtToken
    @PostMapping(value = "/queryMyDelivery")
    public RestApiResult queryMyDelivery(@RequestBody PageVo pageVo) {
        log.info("【投递模块-应届生查询投递接口-参数】:[{}]", pageVo);
        PageEntity<DeliveryEntity> pageEntity = deliveryService.queryByGid(pageVo);
        log.info("【投递模块-应届生查询投递接口-成功】:[{}]", ResultMessage.Delivery.DELIVERY_QUERY_SUCCESS);
        return RestApiResult.ok(pageEntity);
    }

    /**
     * 撤销投递接口
     *
     * @param deliveryRevokeVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/revokeDelivery")
    public RestApiResult revokeDelivery(@RequestBody DeliveryRevokeVO deliveryRevokeVO) {
        log.info("【投递模块-撤销投递接口-参数】deliveryRevokeVO:[{}]", deliveryRevokeVO);
        Integer integer = deliveryService.revokeDelivery(deliveryRevokeVO);
        if (!integer.equals(RecommendConstant.OPERATION_SUCCESS)) {
            log.error("【投递模块-查询投递接口-失败】deliveryRevokeVO,cause:[{}]", ResultMessage.Delivery.REVOKE_FAILURE);
            return RestApiResult.error(ResultMessage.Delivery.REVOKE_FAILURE);
        }
        log.info("【投递模块-查询投递接口-成功】deliveryRevokeVO:[{}]", ResultMessage.Delivery.REVOKE_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Delivery.REVOKE_SUCCESS);
    }

    /**
     * 删除投递记录
     *
     * @param deliveryDeleteVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/deleteDelivery")
    public RestApiResult deleteDelivery(@RequestBody DeliveryDeleteVO deliveryDeleteVO) {
        log.info("【投递模块-删除投递记录接口-参数】deliveryDeleteVO:[{}]", deliveryDeleteVO);
        Integer integer = deliveryService.deleteDelivery(deliveryDeleteVO);
        if (!integer.equals(RecommendConstant.OPERATION_SUCCESS)) {
            log.error("【投递模块-删除投递记录接口-失败】deliveryDeleteVO,cause:[{}]", ResultMessage.Delivery.DELETE_FAILURE);
            return RestApiResult.error(ResultMessage.Delivery.DELETE_FAILURE);
        }
        log.info("【投递模块-删除投递记录接口-成功】deliveryDeleteVO:[{}]", ResultMessage.Delivery.DELETE_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Delivery.DELETE_SUCCESS);
    }

    /**
     * 热度前五的职位
     * @return
     */
    @PostMapping(value = "/queryDeliveryNumberPosition")
    public RestApiResult queryDeliveryNumberPosition(){
        List<DeliveryNumberPositionDTO> deliveryNumberPositionDTOS = deliveryService.queryDeliveryNumberPosition();
        if (CollectionUtils.isEmpty(deliveryNumberPositionDTOS)){
            return null;
        }
        return RestApiResult.ok(deliveryNumberPositionDTOS);
    }

    /**
     * 热度前五的公司
     * @return
     */
    @PostMapping(value = "/queryDeliveryNumberCompany")
    public RestApiResult queryDeliveryNumberCompany(){
        List<DeliveryNumberCompanyDTO> deliveryNumberCompanyDTOS = deliveryService.queryDeliveryNumberCompany();
        if (CollectionUtils.isEmpty(deliveryNumberCompanyDTOS)){
            return null;
        }
        return RestApiResult.ok(deliveryNumberCompanyDTOS);
    }
}
